#include "newpaper.h"

int grid[3][3]= {{0,0,0},{0,0,0},{0,0,0}};
char name[10];
int hi;
void delay(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock());
}

void nameplayers(SDL_Surface *screen)
{
    int i=0;
    char p1[10],p2[10];
    SDL_Event charpressed;
//610 340
    SDL_Surface *bkg = SDL_LoadBMP("img/name/zze name.bmp");
    SDL_Surface *background = SDL_DisplayFormat(bkg);

    SDL_Surface *box = SDL_LoadBMP("img/name/zzz cases.bmp");
    SDL_Surface *boxes = SDL_DisplayFormat(box);
    SDL_Rect srcbox, destbox;
    srcbox.x = 0;
    srcbox.y = 0;
    srcbox.w = background->w;
    srcbox.h = background->h;
    destbox.x = 185;
    destbox.y = 365;
    destbox.w = background->w;
    destbox.h = background->h;


    SDL_Surface *chara;
    SDL_Surface *character;

    SDL_Rect srcbkg, destbkg;
    SDL_Rect srcchar, destchar;


    srcbkg.x = 0;
    srcbkg.y = 0;
    srcbkg.w = background->w;
    srcbkg.h = background->h;
    destbkg.x = 0;
    destbkg.y = 0;
    destbkg.w = background->w;
    destbkg.h = background->h;
    SDL_BlitSurface(background, &srcbkg, screen, &destbkg);
    SDL_SetColorKey(boxes, SDL_SRCCOLORKEY, SDL_MapRGB(boxes->format, 0, 255, 255));
    SDL_BlitSurface(boxes, &srcbox, screen, &destbox);

    SDL_Flip(screen);
int t=0;

    int done=1;
    while(done)
    {
        while (SDL_PollEvent(&charpressed))
        {
            switch(charpressed.type)
            {
            case SDL_QUIT:
                done=0;
            case SDL_KEYDOWN:
            {
                if (charpressed.key.keysym.sym == SDLK_ESCAPE)
                {
                    done=0;
                }
                else if (charpressed.key.keysym.sym == SDLK_q)
                {
                    chara = SDL_LoadBMP("img/name/a.bmp") ;
                    name[t]='a';t++;
                }
                else if (charpressed.key.keysym.sym == SDLK_b)
                {
                    chara = SDL_LoadBMP("img/name/b.bmp") ;
                    name[t]='b';t++;

                }
                else if (charpressed.key.keysym.sym == SDLK_c)
                {
                    chara = SDL_LoadBMP("img/name/c.bmp") ;
                    name[t]='c';t++;

                }
                else if (charpressed.key.keysym.sym == SDLK_d)
                {
                    chara = SDL_LoadBMP("img/name/d.bmp") ;
                    name[t]='d';t++;

                }





                else if ((charpressed.key.keysym.sym == SDLK_RETURN)||(charpressed.key.keysym.sym == SDLK_KP_ENTER))
                {
                    done=0;break;
                }

                 destchar.x = 187 + 55 * i;
                    p1[i]='a';
                    i++;
                    character=SDL_DisplayFormat(chara);
                    srcchar.x = 0;
                    srcchar.y = 0;
                    srcchar.w = background->w;
                    srcchar.h = background->h;
                    destchar.w = background->w;
                    destchar.h = background->h;
                    destchar.y = 367;
                    SDL_SetColorKey(character, SDL_SRCCOLORKEY, SDL_MapRGB(character->format, 0, 255, 255));
                    SDL_BlitSurface(character, &srcchar, screen, &destchar);
                    SDL_Flip(screen);


            }
            }
        }
    }
    SDL_FillRect( screen, 0, 0 );










}





void checkwin(int grid[3][3],SDL_Surface *screenu)
{
    SDL_Surface *mark ;
    SDL_Surface *marky ;
    SDL_Rect destmark,srcmark;



    int i;
    int win;
    for(i=1; i<=3; i++)
    {
        if(grid[i][1]==1 && grid[i][2]==1 && grid[i][3]==1)
        {
            win=1;
            mark = SDL_LoadBMP("img/paper/xwin.bmp");
            marky = SDL_DisplayFormat(mark);
            srcmark.x = 0;
            srcmark.y = 0;
            srcmark.w = marky->w;
            srcmark.h = marky->h;
            destmark.w = marky->w;
            destmark.h = marky->h;
            destmark.x=0;
            destmark.y=0;
            SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
            SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
        }
        else if(grid[i][1]==2 && grid[i][2]==2 && grid[i][3]==2)
        {
            win=2;
            mark = SDL_LoadBMP("img/paper/owin.bmp");
            marky = SDL_DisplayFormat(mark);
            srcmark.x = 0;
            srcmark.y = 0;
            srcmark.w = marky->w;
            srcmark.h = marky->h;
            destmark.w = marky->w;
            destmark.h = marky->h;
            destmark.x=0;
            destmark.y=0;
            SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
            SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
        }
    }
    for(i=1; i<=3; i++)
    {
        if(grid[1][i]==1 && grid[2][i]==1 && grid[3][i]==1)
        {
            win=1;
            mark = SDL_LoadBMP("img/paper/xwin.bmp");
            marky = SDL_DisplayFormat(mark);
            srcmark.x = 0;
            srcmark.y = 0;
            srcmark.w = marky->w;
            srcmark.h = marky->h;
            destmark.w = marky->w;
            destmark.h = marky->h;
            destmark.x=0;
            destmark.y=0;
            SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
            SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
        }
        else if(grid[1][i]==2 && grid[2][i]==2 && grid[3][i]==2)
        {
            win=2;
            mark = SDL_LoadBMP("img/paper/owin.bmp");
            marky = SDL_DisplayFormat(mark);
            srcmark.x = 0;
            srcmark.y = 0;
            srcmark.w = marky->w;
            srcmark.h = marky->h;
            destmark.w = marky->w;
            destmark.h = marky->h;
            destmark.x=0;
            destmark.y=0;
            SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
            SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
        }
    }
    if(grid[1][1]==1 && grid[2][2]==1 && grid[3][3]==1)
    {
        win=1;
        mark = SDL_LoadBMP("img/paper/xwin.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=0;
        destmark.y=0;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
    else if(grid[1][1]==2 && grid[2][2]==2 && grid[3][3]==2)
    {
        win=2;
        mark = SDL_LoadBMP("img/paper/owin.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=0;
        destmark.y=0;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
    else if(grid[1][3]==1 && grid[2][2]==1 && grid[3][1]==1)
    {
        win=1;
        mark = SDL_LoadBMP("img/paper/xwin.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=0;
        destmark.y=0;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
    else if(grid[1][3]==2 && grid[2][2]==2 && grid[3][1]==2)
    {
        win=2;
        mark = SDL_LoadBMP("img/paper/owin.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=0;
        destmark.y=0;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }

}


void checkgrid(int grid[3][3],SDL_Surface *screenu)
{
    SDL_Surface *mark ;
    SDL_Surface *marky ;
    SDL_Rect destmark,srcmark;


    mark = SDL_LoadBMP("img/paper/o.bmp");

//1x
    if (grid[1][1]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=370;
        destmark.y=200;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//1o
    else if (grid[1][1]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=370;
        destmark.y=200;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }

//2x
    if (grid[1][2]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=370;
        destmark.y=270;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//2o
    else if (grid[1][2]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=370;
        destmark.y=270;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//3x
    if (grid[1][3]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=370;
        destmark.y=340;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//3o
    else if (grid[1][3]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=370;
        destmark.y=340;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//4x
    if (grid[2][1]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=440;
        destmark.y=200;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//4o
    else if (grid[2][1]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=440;
        destmark.y=200;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//5x
    if (grid[2][2]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=440;
        destmark.y=270;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//5o
    else if (grid[2][2]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=440;
        destmark.y=270;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//6x
    if (grid[2][3]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=440;
        destmark.y=340;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//6o
    else if (grid[2][3]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=440;
        destmark.y=340;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//1x
    if (grid[3][1]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=510;
        destmark.y=200;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//1o
    else if (grid[3][1]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=510;
        destmark.y=200;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//1x
    if (grid[3][2]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=510;
        destmark.y=270;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//1o
    else if (grid[3][2]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=510;
        destmark.y=270;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//1x
    if (grid[3][3]==1)
    {
        mark = SDL_LoadBMP("img/paper/x.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=510;
        destmark.y=340;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }
//1o
    else if (grid[3][3]==2)
    {
        mark = SDL_LoadBMP("img/paper/o.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=510;
        destmark.y=340;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    }

//animatefeather();

    int i,j,ij=0;
    for (i=1; i<=3; i++)
    {
        for(j=1; j<=3; j++)
        {
            if (grid[i][j]==0)
            {
                ij=1;
            }
        }
    }

    if (ij==0)
    {
        mark = SDL_LoadBMP("img/paper/tie.bmp");
        marky = SDL_DisplayFormat(mark);
        srcmark.x = 0;
        srcmark.y = 0;
        srcmark.w = marky->w;
        srcmark.h = marky->h;
        destmark.w = marky->w;
        destmark.h = marky->h;
        destmark.x=0;
        destmark.y=0;
        SDL_SetColorKey(marky, SDL_SRCCOLORKEY, SDL_MapRGB(marky->format, 0, 255, 255));
        SDL_BlitSurface(marky, &srcmark, screenu, &destmark);
    };

    checkwin(grid,screenu);









    // Mix_Music *music = NULL;
    // Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);



}
void drawitall(int player,int grid[3][3],SDL_Surface *screenu)
{
    SDL_Surface *bgu = SDL_LoadBMP("img/paper/g12.bmp");
    SDL_Surface *imageu = SDL_DisplayFormat(bgu);
    SDL_Rect destu,srcu;


    destu.x = 0;
    destu.y = 0;
    srcu.x = 0;
    srcu.y = 0;
    srcu.w = imageu->w;
    srcu.h = imageu->h;
    destu.w = imageu->w;
    destu.h = imageu->h;

    SDL_FillRect( screenu, 0, 0 );
    SDL_BlitSurface(imageu, &srcu, screenu, &destu);


    checkgrid(grid,screenu);

}

void animgrid(SDL_Surface *screenu)
{
    SDL_Surface *bgu = SDL_LoadBMP("img/paper/g0.bmp");
    SDL_Surface *imageu = SDL_DisplayFormat(bgu);

    SDL_Rect destu,srcu;

    int i=-1;

    while(i<13)
    {
        i++;
        delay(100);

        switch (i)
        {
        case 0 :
            bgu = SDL_LoadBMP("img/paper/g0.bmp");
            break;
        case 1 :
            bgu = SDL_LoadBMP("img/paper/g1.bmp");
            break;
        case 2 :
            bgu = SDL_LoadBMP("img/paper/g2.bmp");
            break;
        case 3 :
            bgu = SDL_LoadBMP("img/paper/g3.bmp");
            break;
        case 4 :
            bgu = SDL_LoadBMP("img/paper/g4.bmp");
            break;
        case 5 :
            bgu = SDL_LoadBMP("img/paper/g5.bmp");
            break;
        case 6 :
            bgu = SDL_LoadBMP("img/paper/g6.bmp");
            break;
        case 7 :
            bgu = SDL_LoadBMP("img/paper/g7.bmp");
            break;
        case 8 :
            bgu = SDL_LoadBMP("img/paper/g8.bmp");
            break;
        case 9 :
            bgu = SDL_LoadBMP("img/paper/g9.bmp");
            break;
        case 10 :
            bgu = SDL_LoadBMP("img/paper/g10.bmp");
            break;
        case 11 :
            bgu = SDL_LoadBMP("img/paper/g11.bmp");
            break;
        case 12 :
            bgu = SDL_LoadBMP("img/paper/g12.bmp");
            break;
        }
        imageu = SDL_DisplayFormat(bgu);

        destu.x = 0;
        destu.y = 0;
        srcu.x = 0;
        srcu.y = 0;
        srcu.w = imageu->w;
        srcu.h = imageu->h;
        destu.w = imageu->w;
        destu.h = imageu->h;

        SDL_BlitSurface(imageu, &srcu, screenu, &destu);

//Flip the backbuffer to the primary Hardware Video Memory
        SDL_Flip(screenu);

    }
    delay(100);
}

void movefeather(SDL_Surface *screenu,int player)//(screenu,player)
{
    SDL_Surface *slcu;
    switch(player)
    {
    case 1 :
        slcu = SDL_LoadBMP("img/paper/feather1.bmp");
        break;
    case 2 :
        slcu = SDL_LoadBMP("img/paper/feather2.bmp");
        break;
    }
    SDL_Surface *selectu = SDL_DisplayFormat(slcu);
    SDL_Rect desto,srco;
    SDL_SetColorKey( selectu, SDL_SRCCOLORKEY, SDL_MapRGB(selectu->format, 0, 255, 255) );
    SDL_Event event;
    desto.x = 260;
    desto.y = -100;
    srco.x = 0;
    srco.y = 0;
    srco.w = selectu->w;
    srco.h = selectu->h;
    desto.w = selectu->w;
    desto.h = selectu->h;
    int done = 1;
    int anso;
    int xe=1,ye=1,desy=-100;
    while (done)
    {
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT:
                done = 0;
                break;
            case SDL_KEYDOWN:
            {
                if (event.key.keysym.sym == SDLK_ESCAPE)
                {
                    done = 0;
                }
                else if (event.key.keysym.sym == SDLK_DOWN)
                {
                    if(ye==1)
                    {
                        desto.y = -30;
                        ye++;
                        desy=-30;
                        drawitall(player,grid,screenu);
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(ye==2)
                    {
                        desto.y = 40;
                        ye++;
                        desy=40;
                        drawitall(player,grid,screenu);
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(ye==3)
                    {
                        desto.y = -100;
                        ye=1;
                        desy=-100;
                        drawitall(player,grid,screenu);
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                }
                else if (event.key.keysym.sym == SDLK_UP)
                {
                    if(ye==1)
                    {
                        desto.y = 40;
                        ye=3;
                        desy=40;
                        drawitall(player,grid,screenu);
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(ye==2)
                    {
                        desto.y = -100;
                        ye--;
                        desy=-100;
                        drawitall(player,grid,screenu);
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(ye==3)
                    {
                        desto.y = -30;
                        ye--;
                        desy=-30;
                        drawitall(player,grid,screenu);
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                }
                else if (event.key.keysym.sym == SDLK_LEFT)
                {
                    if(xe==1)
                    {
                        desto.x = 400;
                        xe=3;
                        drawitall(player,grid,screenu);
                        desto.y=desy;
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(xe==2)
                    {
                        desto.x = 260;
                        xe--;
                        drawitall(player,grid,screenu);
                        desto.y=desy;
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(xe==3)
                    {
                        desto.x = 330;
                        xe--;
                        drawitall(player,grid,screenu);
                        desto.y=desy;
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                }

                else if (event.key.keysym.sym == SDLK_RIGHT)
                {
                    if(xe==1)
                    {
                        desto.x = 330;
                        xe++;
                        drawitall(player,grid,screenu);
                        desto.y=desy;
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(xe==2)
                    {
                        desto.x = 400;
                        xe++;
                        drawitall(player,grid,screenu);
                        desto.y=desy;
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                    else if(xe==3)
                    {
                        desto.x = 260;
                        xe=1;
                        drawitall(player,grid,screenu);
                        desto.y=desy;
                        SDL_BlitSurface(selectu, &srco, screenu, &desto);
                    }
                }
                else if ((event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER))
                {
                    if(grid[xe][ye]==0)
                    {
                        grid[xe][ye]=player;
                        if(player==1)
                        {
                            player=2;
                        }
                        else if(player==2)
                        {
                            player=1;
                        }
                        drawitall(player,grid,screenu);
                        desto.y=desy;
                        SDL_Flip(screenu);
                        showfeather(screenu,player);
                    }

                }
            }
            SDL_Flip(screenu);
            break;
            }
        }
    }//
    scanf("%d",&anso);
}

void showfeather(SDL_Surface *screenu,int player)//(screenu,player)
{
    SDL_Surface *slcu;
    switch(player)
    {
    case 1 :
        slcu = SDL_LoadBMP("img/paper/feather1.bmp");
        break;
    case 2 :
        slcu = SDL_LoadBMP("img/paper/feather2.bmp");
        break;
    }
    SDL_Surface *selectu = SDL_DisplayFormat(slcu);
    SDL_Rect desto,srco;
    SDL_SetColorKey( selectu, SDL_SRCCOLORKEY, SDL_MapRGB(selectu->format, 0, 255, 255) );
    desto.x = 260;
    desto.y = -100;
    srco.x = 0;
    srco.y = 0;
    srco.w = selectu->w;
    srco.h = selectu->h;
    desto.w = selectu->w;
    desto.h = selectu->h;
    SDL_BlitSurface(selectu, &srco, screenu, &desto);
    SDL_Flip(screenu);
    movefeather(screenu,player);
}

void newpaper(SDL_Surface *screenu)
{
    int player=1;
    nameplayers(screenu);
    animgrid(screenu);
    showfeather(screenu,player);
}
